﻿/***********************************************************************
 * Module:  CPFRegisterService.h
 * Author:  ZHANGHASI
 * Modified: 2020年12月7日 下午 3:49:55
 * Purpose: Declaration of the class CPFRegisterService
 ***********************************************************************/

#ifndef __CPFREGISTERSERVICE_H__
#define __CPFREGISTERSERVICE_H__

#include "CPF/CPFObject.h"


class CPFActivator;

/**
 * \class   CPFRegisterService
 *
 * \brief   插件服务注册类.
 *
 * \author  zhanghs
 * \date    2020/12/8
 */
class CPF_EXPORT CPFRegisterService : public CPFObject
{
public:

   /**
    * \fn   static CPFRegisterService* CPFRegisterService::instance(void);
    *
    * \brief    .
    *
    * \author   zhanghs
    * \date 2020/12/8
    *
    * \return   .
    */
   static CPFRegisterService* instance(void);

   /**
    * \fn   void CPFRegisterService::registerObject(std::string name, void* object);
    *
    * \brief    注册一个服务.
    *
    * \author   zhanghs
    * \date 2020/12/8
    *
    * \param    name    服务名称.
    * \param    object  服务对象.
    */
   void registerObject(std::string name, CPFActivator* object);
   template<typename T>
   void registerObject(T* object)
   {
       const type_info& info = typeid(T);

       std::hash_map<std::string, void*>::iterator iterResult = m_hashService.find(info.name());

       if (iterResult == m_hashService.end())
       {
           m_hashService.insert(std::make_pair(info.name(), object));
       }
   }

   /**
    * \fn   void CPFRegisterService::unregisterObject(std::string name);
    *
    * \brief    取消注册服务.
    *
    * \author   zhanghs
    * \date 2020/12/8
    *
    * \param    name    服务名称.
    */
   void unregisterObject(std::string name);
   template<typename T>
   void unregisterObject()
   {
       const type_info& info = typeid(T);
   };

protected:
    /**
    * \fn  CPFRegisterService::CPFRegisterService();
    *
    * \brief   构造函数.
    *
    * \author  zhanghs
    * \date    2020/12/8
    */
    CPFRegisterService();
    /**
    * \fn  virtual CPFRegisterService::~CPFRegisterService();
    *
    * \brief   析构函数.
    *
    * \author  zhanghs
    * \date    2020/12/8
    */
    virtual ~CPFRegisterService();

private:
    // 服务注册列表
    std::unordered_map<std::string, void*> m_hashService;

};
#endif // __CPFREGISTERSERVICE_H__

